import React, { useEffect, useState } from 'react'
import request from '../../axios/request.js'
import { useNavigate } from 'react-router-dom'
const Index = () => {
  let navigate=useNavigate()
  const [list,setList]=useState([])
  const getData=async()=>{
    const res=await request.post('/api/trip/train',{start:'北京',end:'广州'})
    const{code,data}=res.data
    console.log(res.data)
    if(code==200){
      setList(data)
    }
  }
  useEffect(()=>{
    getData()
  },[])
  const godetail=(id)=>{
    navigate(`/detail/${id}`)
  }
  return (
    <div>
      {
        list.map((item,index)=>{
          return <div key={index} onClick={()=>godetail(item.id)} style={{borderBottom:'1px solid #ccc',height:'100px'}}>
              {item.start}-{item.end}
              {item.startTime}
          </div>
        })
      }
    </div>
  )
}

export default Index
